angular.module("sportsStore")
.constant("dataUrl","http://localhost:5500/products")
.constant("orderUrl","http://localhost:5500/order")
.controller("sportsStoreCtrl",function($scope,$http,dataUrl,$location,orderUrl,cart){
    $scope.kkk="5555";
    $scope.data={};
    $http
        .get(dataUrl)
        .success(function(data) {
        $scope.data.products = data;
        })
        .error(function(error){
        $scope.data.error=error;
        });
    
    $scope.sendOrder=function(shippingDetails){
        $scope.kkk="6666";
        var order=angular.copy(shippingDetails);
        order.products=cart.getProducts();
        $http.post(orderUrl,order)
        .success(function(data){
            $scope.data.orderId=data.id;
            cart.getProducts().length=0;
        })
        .error(function(error){
            $scope.kkk="777";
            $scope.data.orderError=error;
        }).finally(function(){
            $location.path("/complete")
        });
    }
});